{% extends "base.html" %}
{% block title %}预约回执单{% endblock %}
{% block head %}
{{ super() }}
<style>

</style>
{% endblock %}
{% block body %}
<div class="contianer info-page" style="display: flex;flex-direction: column;">

    <div class="weui-well well-print font14">
        <div class="text-center">
            <h2>{{ config.HOSPITAL }}
                <span class="leftRightCicle"></span>
            </h2>
        </div>
        <div class="weui-flex text-center onlyBottomBorder">
            <div class="weui-flex__item">
                <div id="patientInfo"></div>

                <div class="bcTarget" style="margin:0 auto;height: 5em;" barWidth="2" barHeight="46">
                    <input type="hidden" value="123456">
                </div>
                <div class="weui-flex font12 text-disabled">
                    <div class="weui-flex__item">
                        <div id="bedNum"></div>
                        <div id="deptName"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-flex font12 text-disabled">
            <div class="weui-flex__item">检查项目</div>
            <div class="weui-flex__item">部位</div>
            <div class="weui-flex__item" style="text-align: right">方法</div>
        </div>
        <div id="examList" class="onlyBottomBorder"></div>
        {#
        <div class="weui-flex font12 onlyBottomBorder">#}
            {#
            <div class="weui-flex__item">11</div>
            #}
            {#
            <div class="weui-flex__item">11</div>
            #}
            {#
            <div class="weui-flex__item" style="text-align: right">11</div>
            #}
            {#
        </div>
        #}

        <div class="onlyBottomBorder">
            <div>预约日期：<span id="examDate" class="text-red font-bold"></span></div>
            <div>报到时间：<span id="examTime" class="text-red font-bold"></span></div>
            <div>检查地址：<span id="examAddress" class="text-red font-bold"></span></div>
        </div>
        <div class="text-disabled">
            <small class="font-bold">
                <span class="font14 text-red">【注意事项】</span><br>
                <span id="attention" class="font14 text-blank"></span><br>
                <span class="font14 text-green">【温馨提醒】</span><br>
                <span id="remind" class="font14 text-blank"></span><br>
                <span class="font14 text-common">【就诊当天凭本单执行检查，请妥善保管】</span>
            </small>
        </div>
    </div>
</div>
{% endblock %}
{% block script %}
{{ super() }}
<script src="{{ url_for('page.send_static',filename='js/jquery-barcode.min.js') }}"></script>
<script type="text/javascript">
        Array.prototype.unique = function(arr){
            var result = [];
            for (var i = 0; i < this.length; i++) {
                 if (result.indexOf(this[i]) == -1) {
                     result.push(this[i]);
                 }
            }
            return result;
        }
        $(function () {
            var id = common.getQueryString("id");
            $.getJSON(navRoot + '/api/res/hz', {"id": id}, function (data) {
                if (data["code"] == 200) {
                    var resInfo = data["data"]["data"];
                    $("#patientInfo").text(resInfo["PatientObj"]["name"] + " " + resInfo["PatientObj"]["sex"] + " " + resInfo["PatientObj"]["age"]);
                    if (resInfo["PatientObj"]["bedNumber"]) {
                        $("#bedNum").text("床位：" + resInfo["PatientObj"]["bedNumber"]);
                    }
                    $("#deptName").text("诊室：" + resInfo["PatientObj"]["department"]);
                    $("#examDate").text(common.dateFormart(resInfo["ReservationDate"], "yyyy-MM-dd"));
                    $("#examTime").text(resInfo["ReservationTime"]);
                    $("#examAddress").text(resInfo["ExamPlace"]);
                    $(".bcTarget").find("input").val(resInfo["ScheduleID"]);
                    var examList = resInfo["ExamList"];
                    var examCount = examList.length;
                    var ready = "";
                    var remind = "";
                    for (var i = 0; i < examCount; i++) {
                        var exam = $('<div class="weui-flex font12" style="padding:5px 0;">' +
                            '                <div class="weui-flex__item">' + (examCount > 1 ? i + 1 : '') + '[' + examList[i]['inspection'] + ']' + examList[i]['project'] + '</div>' +
                            '                <div class="weui-flex__item">' + examList[i]['bodyPart_second'] + '</div>' +
                            '                <div class="weui-flex__item" style="text-align: right">' + examList[i]['inspectionMethod'] + '</div>' +
                            '            </div>');
                        $("#examList").append(exam);

                        ready += examList[i]['prepare'] ? (examCount > 1 ? '第' + i + 1 + '项检查：' : '') + examList[i]['prepare'] + '<br>' : '';
                        remind += examList[i]['reminder'] ? (examCount > 1 ? '第' + i + 1 + '项检查：' : '') + examList[i]['reminder'] + '<br>' : '';
                    }
                    if (ready == "") {
                        ready = "<span class='text-disabled'>无</span><br>"
                    }
                    $('#attention').append(ready);
                    if (remind == "") {
                        remind = "<span class='text-disabled'>无</span><br>"
                    }
                    $('#remind').append(remind);
                    
                    $(".bcTarget").each(function (i, targetQRDiv) {
                        var $targetQRDiv = $(targetQRDiv);
                        if ($targetQRDiv && $targetQRDiv.children("input").val()) {
                            targetStr = $targetQRDiv.children("input").val();
                            targetWidth = $targetQRDiv.attr("barWidth");
                            if (!targetWidth) {
                                targetWidth = 20;
                            }
                            targetHeight = $targetQRDiv.attr("barHeight");
                            if (!targetHeight) {
                                targetHeight = 0;
                            }
			    targetHeight = 0;
                            targetType = $targetQRDiv.attr("datatype");
                            if (targetType == "qrcode") {
                                $targetQRDiv.qrcode({render: "canvas", width: 200, height: 200, text: targetStr});
                                $targetQRDiv.children("canvas").css('width', 200).css('height', 200);
                                $targetQRDiv.addClass("text-center");
                            } else {
                                var encode = "code128";
                                //if (8 === targetStr.length) encode = "ean8";
                                //else if (13 === targetStr.length) encode = "ean13";
                                $targetQRDiv.barcode(targetStr, encode, {
                                    barWidth: targetWidth,
                                    barHeight: targetHeight,
                                    showHRI: true,
                                    bgColor: "#fff"
                                });
                            }
                        }
                    })
                } else {
                    $.alert(data['errmsg']);
                }
            })

            //直接从预约信息读取，取消从接口读取
            /*$.post(navRoot + "/api/res/careDeatil",  {"id": id}, function (data) {
                if(data["code"]==200){
                    var list = [];
                    try{
                        if (data["data"]["List"]) {
                            var dataObj = data["data"]["List"]["RequisitionFindResult"]["MedicalRequestInfo"]["RequestInfo"];
                            if (!dataObj.hasOwnProperty("length")) {
                                list[0] = dataObj;
                            } else {
                                list = dataObj;
                            }
                            var reayArr = [],reminArr = [];
                            for (var i=0;i<list.length;i++) {
                                var obj = list[i].ExamList.Exam;
                                var examList=[];
                                if (!obj.hasOwnProperty("length")) {
                                    examList[0] = obj;
                                }else{
                                    examList=obj;
                                }
                                for(var j=0;j<examList.length;j++){
                                    var ready = examList[j].ExamReady;
                                    if(ready!=null&&ready!=""&&ready!="null"){
                                        reayArr.push(ready.trim());
                                    }
                                    var rem = examList[j].ExamReminder;
                                    if(rem!=null&&rem!=""&&rem!="null"){
                                        reminArr.push(rem.trim());
                                    }

                                }
                            }
                            reayArr.unique().forEach(function(ready,index){
                                $('#attention').append(parseInt(index+1)+". "+ready+"；<br>");
                            });
                            reminArr.unique().forEach(function(remin,index){
                                $('#remind').append(parseInt(index+1)+". "+remin+"；<br>");
                            });
                        }
                    }catch(err){
                        $.alert("数据错误:" + err);
                    }
                }else if (data["code"] == 501) {
                    $('#attention').text("暂无数据");
                } else {
                    $.alert(data["errmsg"]);
                }
            }, "json");*/
        })

</script>
{% endblock %}
